package fengstyle.controller;

import fengstyle.po.TOrder;
import fengstyle.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/order/add")
    public String add(Long id, String no, String userName, String date) throws ParseException {
        TOrder order = new TOrder();
        order.settId(id);
        order.settNO(no);
        order.settName(userName);
        Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
        order.setChangeDate(d);
        orderService.add(order);
        return "sucess";
    }

    @GetMapping("/order/list")
    public List<TOrder> getList(String startDate, String endDate) throws ParseException {
        return orderService.getList(startDate, endDate);
    }
}
